import asyncio


async def producer(queue, items):
    for item in items:
        print(f"Producing {item}")
        await queue.put(item)
        await asyncio.sleep(1)


async def consumer(queue):
    while True:
        item = await queue.get()
        if item is None:  # 结束信号
            break
        print(f"Consuming {item}")
        await asyncio.sleep(2)


async def main():
    queue = asyncio.Queue()
    producer_task = asyncio.create_task(producer(queue, range(5)))
    consumer_task = asyncio.create_task(consumer(queue))

    await producer_task
    await queue.put(None)  # 发送结束信号
    await consumer_task


asyncio.run(main())